<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :showAttrs="showAttrs"
                :exportApiName="exportApiName"
    >
      <template v-slot:header>
        <el-button size="small" type="warning" @click="openChartDialog">图表</el-button>
        <el-button size="small" type="primary" @click="multiplyDayProductCount">批量新增</el-button>
        <el-button size="small" type="success" @click="multiplyUpdateDayProductCount">批量修改</el-button>
      </template>
    </table-view>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!--  图表对话框  -->
    <normal-chart-dialog ref="charDialog"
                         :chartTypes="chartTypes"
                         :chartSearchObj="chartSearchObj"
                         :commitChartSearch="commitChartSearch"
    >
      <template v-slot:chart="{chart}">
        <line-chart v-if="R.equals('line', chart.chartType)" ref="chart"></line-chart>
        <pie-chart v-if="R.equals('pie', chart.chartType)" ref="chart"></pie-chart>
      </template>
    </normal-chart-dialog>

    <el-dialog
      title="批量新增每日生产"
      :visible="dayProductCountVisible"
      :close-on-click-modal="false"
      :before-close="handleClose"
      :fullscreen="true"
      width="90%">

      <el-form
        ref="dataForm"
        label-width="140px"
        label-position="left"
        style="margin-left:30px"
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
      >

        <el-form-item label="上一个班别" style="width: 400px" v-if="!updateFlag">
          <el-select v-model="beforeClassId" clearable filterable placeholder="班次"  @change="changeDayTime()">
            <el-option label="白班" :value=1>白班</el-option>
            <el-option label="中班" :value=2>中班</el-option>
            <el-option label="夜班" :value=3>夜班</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期" style="width: 400px">
          <el-date-picker
            v-model="dayTime"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions"
            @change="changeDayTime()"
          >
          </el-date-picker>
        </el-form-item>

        <template v-for="(dayProduction,j) of dayBatchProductionList">
          <el-divider content-position="center"> {{j==0?'1#8S':j==1?'2#-8S':j==2?'3#-8S':j==3?'4#-9S':j==4?'5#-8S':'其它'}}</el-divider>
          <!--        1#8S-->
          <el-form-item :label="j==0?'1#8S':j==1?'2#-8S':j==2?'3#-8S':j==3?'4#-9S':j==4?'5#-8S':'其它'" style=" width: 400px">
            <el-select v-model="dayProduction.deviceId"  clearable filterable placeholder="请选择">
              <el-option
                v-for="item in productDeviceList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="机速" style="width: 400px">
            <el-input-number @change="changeDripLiquid(j)" controls-position="right" :precision="2" size="small" :min="0"
                             v-model="dayProduction.machineSpeed" placeholder="机速"></el-input-number>
          </el-form-item>


          <el-form-item label="机台" style="width: 400px">
            <el-input-number @change="changeDripLiquid(j)" controls-position="right" size="small" :min="0"
                             v-model="dayProduction.duration" placeholder="时长"></el-input-number>
          </el-form-item>

          <el-form-item label="滴料（机速*机台）" style="width: 400px">
            <el-input-number @change="changeDripLiquid(j)" controls-position="right" size="small" :min="0"
                             v-model="dayProduction.dripLiquid" placeholder="滴料"></el-input-number>
          </el-form-item>

          <el-form-item label="工时时长" style="width: 400px">
            <el-input-number @change="changeDripLiquid(j)" controls-position="right"  size="small" :min="0"
                             v-model="dayProduction.timerNumber" placeholder="工时时长"></el-input-number>
          </el-form-item>
<!--          remark-->
          <el-form-item label="换产备注" prop="remark">
            <el-input type="textarea" style="width:50%" rows="3" v-model="dayProduction.remark" placeholder="备注">

            </el-input>
          </el-form-item>
          <el-table
            :data="dayProduction.processOrderDetailList"
            border

            style="display: inline-block;width: 100%">

            <el-table-column
              prop="id"
              label="订单编号"
              align="center"
              width="180"
            >
              <template slot-scope="scope">
                <el-select v-model="scope.row.orderDetailId" filterable :filter-method="orderDetailFilterList" clearable
                           @change="funcAttrGet(scope.row.orderDetailId,scope.$index,j)" placeholder="请选择">
                  <el-option
                    v-for="item in orderDetailListFilter"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>


      <!--      <el-table-column
              prop="productNo"
              label="产品名称"
              align="center"
              width="150"
            >
              <template slot-scope="scope">
                <el-input v-model="scope.row.productNo" placeholder="请选择"></el-input>
              </template>
            </el-table-column>-->


            <el-table-column
              prop="classId"
              label="班次"
              align="center"
              width="110"
            >
              <template slot-scope="scope">
                <el-select v-model="scope.row.classId" clearable filterable placeholder="班次">
                  <el-option label="白班" :value=1>白班</el-option>
                  <el-option label="中班" :value=2>中班</el-option>
                  <el-option label="夜班" :value=3>夜班</el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column
              prop="duration"
              label="机台"
              align="center"
              width="110"
            >
              <template slot-scope="scope">
                <el-select v-model="scope.row.duration" clearable filterable placeholder="机台" @change="changeProductNumber(scope.$index,j)">
                  <el-option
                    v-for="item in durationList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column
              prop="userId"
              label="员工"
              width="110"
              align="center"
            >
              <template slot-scope="scope">

                <el-select v-model="scope.row.userId" clearable filterable placeholder="员工">
                  <el-option
                    v-for="item in userInfoList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column
              prop="boxPieceNumber"
              label="箱只"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" @change="changeNumber(scope.$index,j)"
                                 v-model="scope.row.boxPieceNumber" placeholder="箱只"></el-input-number>
              </template>
            </el-table-column>


            <el-table-column
              prop="boxNumber"
              label="箱数"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" @change="changeNumber(scope.$index,j)"
                                 v-model="scope.row.boxNumber" placeholder="箱数"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="scrapNumber"
              label="零头"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" @change="changeNumber(scope.$index,j)"
                                 v-model="scope.row.scrapNumber" placeholder="零头"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="productNumber"
              label="数量"
              width="150"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0"
                                 v-model="scope.row.productNumber" placeholder="数量" @change="changeProductNumber(scope.$index,j)"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="lightGlassPrice"
              label="光瓶单价"
              width="150"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" v-model="scope.row.lightGlassPrice"
                                 placeholder="光瓶单价"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="productionState"
              label="生产状态"
              align="center"
              width="110"
            >
              <template slot-scope="scope">
                <el-select v-model="scope.row.productionState" clearable filterable placeholder="生产状态">
                  <el-option label="上机" :value=0>上机</el-option>
                  <el-option label="继续生产" :value=5>继续生产</el-option>
                  <el-option label="下机" :value=10>下机</el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="actualProductWeight"
              label="实际克重"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" :precision="2"
                                 v-model="scope.row.actualProductWeight"  @change="changeProductNumber(scope.$index,j)" placeholder="实际克重"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="productWeight"
              label="订单单重"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" :precision="2"
                                 v-model="scope.row.productWeight" placeholder="单重"></el-input-number>
              </template>
            </el-table-column>

<!--            -->


            <el-table-column
              prop="dischargeVolume"
              label="出料量"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" size="small" :min="0" :precision="2"
                                 v-model="scope.row.dischargeVolume" placeholder="出料量"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column
              prop="countWeight"
              label="总重"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" disabled size="small" :min="0" v-model="scope.row.countWeight"
                                 placeholder="总重"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              prop="successRate"
              label="合格率"
              width="130"
              align="center"
            >
              <template slot-scope="scope">
                <el-input-number controls-position="right" disabled size="small" :min="0" v-model="scope.row.successRate"
                                 placeholder="合格率"></el-input-number>
              </template>
            </el-table-column>

            <el-table-column
              fixed="right"
              label="操作"
              width="100px"

            >
              <template slot-scope="scope">
                <el-button
                  @click="addRow(j,scope.$index)"
                  size="small"
                  type="success"
                  icon="el-icon-plus"
                  circle>
                </el-button>
                <el-button v-if="dayProduction.processOrderDetailList.length>1"
                           size="small"
                           @click="deleteRow(j,scope.$index)"
                           icon="el-icon-delete"
                           type="danger"
                           circle>

                </el-button>

              </template>
            </el-table-column>
          </el-table>
         <div style="margin-top: 20px" v-if="beforeClassId==3">
            <el-tag type="success">白班：</el-tag>
          </div>
          <div style="margin-top: 20px" v-if="beforeClassId==1">
            <el-tag type="warning">中班：</el-tag>
          </div>

          <div style="margin-top: 20px" v-if="beforeClassId==2">
            <el-tag type="warning">晚班：</el-tag>
          </div>
          <div style="margin-top: 20px">
            <el-tag type="success">产量小记： {{dayBatchProductionList[j].classCountProductNumber}}</el-tag>
            <div style="margin-top: 10px"></div>
            <el-tag type="danger">滴料量小记：{{dayBatchProductionList[j].classCountDischargeVolume}}</el-tag>
          </div>

        </template>

      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dayProductCountVisible = false">取 消</el-button>
        <el-button type="primary" :loading="loading" @click="multiplySaveDayProduction">确 定</el-button>
      </span>

    </el-dialog>
  </div>
</template>

<script>
  import AddOrUpdate from './dayproductcount-add-or-update'
  import tableView from '@/components/tableView'
  import basicMixins from '@/utils/commonViewMixins'
  import lineChart from '@/views/charts/day/dayProductCountLineChart'
  import pieChart from '@/views/charts/day/dayProductCountPieChart'
  import {mRequest, mRequestPromise} from '@/utils/request'
  export default {
    mixins: [basicMixins],
    data() {
      return {
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]
        },
        loading: false,
        chartSearchObj: {
          dataForm: {
            dateTimeRange: []
          },
          config: {
            dateTimeRange: {
              type: 'date',
              clearable: true,
              dateType: 'daterange',
              label: '时间范围'
            }
          }
        },
        beforeClassId: 1,
        dayProductCountVisible: false,
        productDeviceList: [],
        deviceIdList: [],
        orderDetailList: [],
        productInfoList: [],
        orderDetailListFilter: [],
        productInfoListFilter: [],
        userInfoList: [],
        tableListData: [{
          orderDetailId: '',
          productId: '',
          classId: '',
          userId: '',
          successRate: 0,
          countWeight: 0,
          lightGlassPrice: 0,
          productWeight: '',
          actualProductWeight: '',
          boxPieceNumber: '',
          productNumber: '',
          boxNumber: '',
          productionState: 0
        }],
        durationList:[
          {'id':1,'name':'1号台'},
          {'id':2,'name':'2号台'},
          {'id':3,'name':'3号台'},
          {'id':4,'name':'4号台'},
          {'id':5,'name':'5号台'},
          {'id':6,'name':'6号台'},
          {'id':-1,'name':'打样'},
        ],
        dayBatchProductionList: [
          //1
          {
            deviceId: 1,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 8,
            remark: '',
            classCountProductNumber: 0,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              actualProductWeight: '',
              actualCountWeight: '',
              productWeight: '',
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              scrapNumber: 0, //零头
              dischargeVolume: '',   //出料量
              productionState: 0
            }
            ],
          },
          //2
          {
            deviceId: 2,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 8,
            remark: '',
            classCountProductNumber: 0,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              productWeight: '',
              actualProductWeight: '',
              actualCountWeight: '',
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              scrapNumber: 0, //零头
              dischargeVolume: '',
              productionState: 0
            }
            ],
          },
          //3
          {
            deviceId: 3,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 8,
            remark: '',
            classCountProductNumber: 0,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              productWeight: '',
              actualProductWeight: '',
              actualCountWeight: '',
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              scrapNumber: 0, //零头
              dischargeVolume: '',
              productionState: 0
            }
            ],
          },
          //4
          {
            deviceId: 4,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 8,
            remark: '',
            classCountProductNumber: 0,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              productWeight: '',
              actualProductWeight: '',
              actualCountWeight: '',
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              scrapNumber: 0, //零头
              dischargeVolume: '',
              productionState: 0
            }
            ],
          },
          //5
          {
            deviceId: 5,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 8,
            remark: '',
            classCountProductNumber: 0,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              productWeight: '',
              actualProductWeight: '',
              actualCountWeight: 0,
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              scrapNumber: 0, //零头
              dischargeVolume: '',
              productionState: 0
            }
            ],
          },
          //6
          // {
          //   deviceId: 6,
          //   dripLiquid: 0,
          //   duration: 0,
          //   machineSpeed: 0,
          //   timerNumber: 8,
          //   remark: '',
          //   classCountProductNumber: 0,
          //   processOrderDetailList: [{
          //     orderDetailId: '',
          //     productId: '',
          //     classId: '',
          //     userId: '',
          //     successRate: 0,
          //     countWeight: 0,
          //     lightGlassPrice: 0,
          //     productWeight: '',
          //     actualProductWeight: '',
          //     actualCountWeight: 0,
          //     boxPieceNumber: '',
          //     productNumber: '',
          //     boxNumber: '',
          //     scrapNumber: 0, //零头
          //     dischargeVolume: '',
          //     productionState: 0
          //   }
          //   ],
          // },
          //7
      /*    {
            deviceId: 7,
            dripLiquid: 0,
            duration: 0,
            machineSpeed: 0,
            timerNumber: 12,
            processOrderDetailList: [{
              orderDetailId: '',
              productId: '',
              classId: '',
              userId: '',
              successRate: 0,
              countWeight: 0,
              lightGlassPrice: 0,
              productWeight: '',
              actualProductWeight: '',
              actualCountWeight: 0,
              boxPieceNumber: '',
              productNumber: '',
              boxNumber: '',
              dischargeVolume: '',
              productionState: 0
            }
            ],
          },*/
        ],
        dayTime: '',
        deviceIdOne: 1,
        dripLiquid: 0,
        duration: 0,
        machineSpeed: 0,
        chartTypes: [
          {label: 'pie', text: '饼状图'},
          {label: 'line', text: '折线图'}
        ],
        updateFlag: false,
        searchAttrs: {
          dateTimeRange: {
            type: 'date',
            dateType: 'daterange',
            clearable: true
          },
          deviceId: {
            type: 'autoComplete',
            placeholder: '请选择设备',
            querySearchApiName: 'productApi/getProductDeviceList'
          },
          classId: {
            type: 'autoComplete',
            placeholder: '班次',
            querySearchApiName: 'userApi/getUserInfoList'
          },
          productId: {
            type: 'autoComplete',
            placeholder: '请选择产品',
            querySearchApiName: 'productApi/getProductInfoList'
          },


        },
        primaryKey: 'id',
        listApiName: 'dayApi/listDayProductList',
        deleteApiName: 'dayApi/deleteDayProductCount',
        exportApiName: 'dayApi/getDayProductStatisticExport',
        saveAuthName: 'day:dayproductcount:save',
        deleteAuthName: 'day:dayproductcount:delete',
        showAttrs: {
          deviceName: {label: '料道'},
          classesName: {label: '班别'},
          userName: {label: '员工'},
          orderDetailNo: {label: '订单编号'},
          productNo: {label: '产品名称'},
          productionState: {
            label: '生产状态',
            type: 'radio',
            items: [
              {value: 0, text: '上线', tagType: 'success'},
              {value: 5, text: '继续生产'},
              {value: 10, text: '下机', tagType: 'danger'}

            ]
          },
          dayTime: {label: '生产日期', type: 'date', width: 100},
          productNumber: {label: '生产只数'},
          productWeight: {label: '单重'},
          actualProductWeight: {label: '实际重量'},
          lightGlassPrice: {label: '单价'},
          countProductValue: {label: '产值'},
          countWeightTon: {label: '总重量(t)'},
          machineSpeed: {label: '机速'},
          duration: {label: '机台'},
          dischargeVolume: {label: '出料量'},
          successRate: {label: '单品成品率', width: 100,type: 'tagRange'},
          userDaySuccessRate: {label: '班次成品率', width: 100},
          deviceSuccessRate: {label: '设备成品率', width: 100},
          boxPieceNumber: {label: '箱只'},
          boxNumber: {label: '箱数'},
        /*  status: {
            label: '状态',
            type: 'radio',
            items: [
              {value: 0, text: '禁用', tagType: 'danger'},
              {value: 1, text: '正常'}
            ]
          }*/
        }
      }
    },
    components: {
      AddOrUpdate,
      tableView,
      lineChart,
      pieChart
    },
    methods: {
      multiplyDayProductCount() {
        this.dayProductCountVisible = true
        this.loading = false
        this.updateFlag = false
        this.tableListData = [{
          orderDetailId: '',
          productId: '',
          classId: '',
          userId: '',
          successRate: 0,
          countWeight: 0,
          productWeight: '',
          boxPieceNumber: '',
          productNumber: '',
          boxNumber: '',
          productionState: 0,
          actualProductWeight: '',
          actualCountWeight: 0,
          dischargeVolume: '',
        }]
        this.dayTime = ''
        this.deviceIdOne = 1
        this.dripLiquid = 0
        this.duration = 0
        this.machineSpeed = 0
        this.initOrderDetailList()
        this.initUserInfoList()
        this.initProductDeviceList()
      },
      multiplyUpdateDayProductCount() {
        this.dayProductCountVisible = true
        this.updateFlag = true
        this.loading = false
        this.tableListData = [{
          orderDetailId: '',
          productId: '',
          classId: '',
          userId: '',
          successRate: 0,
          countWeight: 0,
          productWeight: '',
          boxPieceNumber: '',
          productNumber: '',
          boxNumber: '',
          productionState: 0,
          actualProductWeight: '',
          actualCountWeight: 0,
          dischargeVolume: '',
        }]
        this.dayTime = ''
        this.deviceIdOne = 1
        this.dripLiquid = 0
        this.duration = 0
        this.machineSpeed = 0
        this.initOrderDetailList()
        this.initUserInfoList()
      },
      deleteRow(i,index) {
        this.dayBatchProductionList[i].processOrderDetailList.splice(index, 1);
        this.orderDetailListFilter=this.orderDetailList
      },
      addRow(i,index) {
        let _object = {
          orderDetailId: '',
          productId: '',
          classId: this.dayBatchProductionList[i].processOrderDetailList[index].classId,
          userId: this.dayBatchProductionList[i].processOrderDetailList[index].userId,
          successRate: 0,
          countWeight: 0,
          lightGlassPrice: 0,
          productWeight: '',
          boxPieceNumber: '',
          productNumber: '',
          boxNumber: '',
          scrapNumber: 0, //零头
          productionState: 0,
          actualProductWeight: '',
          actualCountWeight: 0,
          dischargeVolume: '',
        }
         this.dayBatchProductionList[i].processOrderDetailList.push(_object);
      },
      initProductDeviceList() {
        mRequest('productApi/getProductDeviceList', {}, (res) => {
          this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
        })
      },
      initUserInfoList() {
        mRequest('userApi/getUserInfoList', {}, (res) => {
          this.userInfoList = this.R.pathOr([], ['data', 'list'], res)
        })
      },
      initOrderDetailList() {
        mRequest('orderApi/listOrderDetailProcessing', {}, (res) => {
          this.orderDetailList = this.R.pathOr([], ['data', 'list'], res)
          this.orderDetailFilterList()
        })
      },
      funcAttrGet(orderDetailId, index,j) {
          mRequest('orderApi/orderDetailInfo', {id: orderDetailId}, ({data}) => {
          this.dayBatchProductionList[j].processOrderDetailList[index].productId = this.R.pathOr(0, ['orderDetail', 'productId'], data)
          this.dayBatchProductionList[j].processOrderDetailList[index].productNo = this.R.pathOr(0, ['orderDetail', 'productNo'], data)
          this.dayBatchProductionList[j].processOrderDetailList[index].lightGlassPrice = this.R.pathOr(0, ['orderDetail', 'lightGlassPrice'], data)
          this.dayBatchProductionList[j].processOrderDetailList[index].productWeight = this.R.pathOr(0, ['orderDetail', 'productWeight'], data)
        })

      },
      changeNumber(index,j) {

        this.dayBatchProductionList[j].processOrderDetailList[index].productNumber =
          (this.dayBatchProductionList[j].processOrderDetailList[index].boxPieceNumber * this.dayBatchProductionList[j].processOrderDetailList[index].boxNumber)
          +this.dayBatchProductionList[j].processOrderDetailList[index].scrapNumber
        this.dayBatchProductionList[j].processOrderDetailList[index].actualCountWeight = this.dayBatchProductionList[j].processOrderDetailList[index].actualProductWeight * this.dayBatchProductionList[j].processOrderDetailList[index].productNumber

        this.dayBatchProductionList[j].processOrderDetailList[index].countWeight = this.dayBatchProductionList[j].processOrderDetailList[index].productWeight * this.dayBatchProductionList[j].processOrderDetailList[index].productNumber
        if (0 != this.dayBatchProductionList[j].machineSpeed && 0 != this.dayBatchProductionList[j].duration) {
        //  this.dayBatchProductionList[j].machineSpeed = this.dayBatchProductionList[j].dripLiquid / this.dayBatchProductionList[j].duration
          this.dayBatchProductionList[j].dripLiquid = this.dayBatchProductionList[j].machineSpeed * this.dayBatchProductionList[j].duration
        }
        if (0 != this.dayBatchProductionList[j].machineSpeed) {
          this.dayBatchProductionList[j].processOrderDetailList[index].successRate = (this.dayBatchProductionList[j].processOrderDetailList[index].productNumber /
            (this.dayBatchProductionList[j].machineSpeed * 60 * this.dayBatchProductionList[j].timerNumber) * 100).toFixed(2)
        }
        let productNumberArray=window.R.pluck('productNumber', this.dayBatchProductionList[j].processOrderDetailList)
        let classCountProductNumber=0
        let mySubtract = function (a, b) {
          return a + b;
        };
        classCountProductNumber = window.R.reduce(mySubtract, classCountProductNumber)(productNumberArray)
        this.dayBatchProductionList[j].classCountProductNumber=classCountProductNumber
      },
      changeProductNumber(index, j) {
        this.dayBatchProductionList[j].processOrderDetailList[index].countWeight = this.dayBatchProductionList[j].processOrderDetailList[index].productWeight * this.dayBatchProductionList[j].processOrderDetailList[index].productNumber
        this.dayBatchProductionList[j].processOrderDetailList[index].actualCountWeight = this.dayBatchProductionList[j].processOrderDetailList[index].actualProductWeight * this.dayBatchProductionList[j].processOrderDetailList[index].productNumber
        if (0 != this.dayBatchProductionList[j].machineSpeed && 0 != this.dayBatchProductionList[j].duration) {
          this.dayBatchProductionList[j].dripLiquid = this.dayBatchProductionList[j].machineSpeed * this.dayBatchProductionList[j].duration
        }
        if (0 != this.dayBatchProductionList[j].machineSpeed) {

          let groupUserIdMap = window.R.groupBy(window.R.prop('userId'), this.dayBatchProductionList[j].processOrderDetailList)

          let nowUserId =this.dayBatchProductionList[j].processOrderDetailList[index].userId

          let  groupDurationMap=  window.R.groupBy(window.R.prop('duration'), groupUserIdMap[nowUserId])
          //TODO 其他的机台也要变化
          let classCountDischargeVolume = 0

          for(var nowDurationId in groupDurationMap){
            let durationProductNumberArray = window.R.pluck('productNumber', groupDurationMap[nowDurationId])
            let mySubtract = function (a, b) {
              return a + b;
            };
            let durationProductNumber=   window.R.reduce(mySubtract, 0)(durationProductNumberArray)
            console.log('durationProductNumber ' + durationProductNumber)
            let i=0
            groupDurationMap[nowDurationId].forEach(item=>{

              item.successRate =( durationProductNumber / (this.dayBatchProductionList[j].machineSpeed * 60 * this.dayBatchProductionList[j].timerNumber) * 100).toFixed(2)
              item.dischargeVolume = ((item.actualProductWeight*this.dayBatchProductionList[j].machineSpeed * 60 * this.dayBatchProductionList[j].timerNumber)/1000000).toFixed(3)
              if (i == 0) {
                classCountDischargeVolume += item.dischargeVolume
                item.status = 0
              }else {
                item.status=1
              }
              i++
            })
          }
          this.dayBatchProductionList[j].classCountDischargeVolume = classCountDischargeVolume



          // let nowDurationId= this.dayBatchProductionList[j].processOrderDetailList[index].duration


        //  this.dayBatchProductionList[j].processOrderDetailList[index].successRate = durationProductNumber / (this.dayBatchProductionList[j].machineSpeed * 60 * 12) * 100
        }
      },
      changeDripLiquid(j) {

        if (0 != this.dayBatchProductionList[j].machineSpeed && 0 != this.dayBatchProductionList[j].duration) {
        //  this.dayBatchProductionList[j].machineSpeed = this.dayBatchProductionList[j].dripLiquid / this.dayBatchProductionList[j].duration
          this.dayBatchProductionList[j].dripLiquid = this.dayBatchProductionList[j].machineSpeed * this.dayBatchProductionList[j].duration
        }
        if (0 != this.dayBatchProductionList[j].machineSpeed) {
          for (let index = 0; index < this.dayBatchProductionList[j].processOrderDetailList.length; index++) {
            this.dayBatchProductionList[j].processOrderDetailList[index].successRate =
              (this.dayBatchProductionList[j].processOrderDetailList[index].productNumber
                / (this.dayBatchProductionList[j].machineSpeed * 60 * this.dayBatchProductionList[j].timerNumber) * 100).toFixed(2)

          }
        }
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
            this.dayProductCountVisible = false
          })
          .catch(_ => {
          });
      },
      multiplySaveDayProduction() {
        this.loading = true
        const saveOrUpdateApi = this.updateFlag ? 'dayApi/multiplyUpdateDayProduction' : 'dayApi/multiplySaveDayProduction'
        mRequest(saveOrUpdateApi, {
          'dayTime': this.dayTime,
          'dayBatchProductionList': this.dayBatchProductionList
        }, (res => {
          let data = res.data

          if (data && data.code == 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.dayProductCountVisible = false
                this.loading = false
                this.getDataList()
                this.$emit('refreshDataList')
              }
            })

          } else {
            this.$message.error(data.msg)
            this.loading = false
          }
        }))
      },
      orderDetailFilterList(query = '') {
        const arr = this.orderDetailList.filter(item => {
          return item.name.toLowerCase().includes(query.toLowerCase())
        })

        if (arr.length > 100) {
          this.orderDetailListFilter = arr.slice(0, 100)
        } else {
          this.orderDetailListFilter = arr
        }
      },
      productInfoFilterList(query = '') {
        const arr = this.productInfoList.filter(item => {
          return item.name.toLowerCase().includes(query.toLowerCase())
        })

        if (arr.length > 100) {
          this.productInfoListFilter = arr.slice(0, 100)
        } else {
          this.productInfoListFilter = arr
        }
      },
       changeDayTime() {
        if (this.dayTime) {
          this.loading = true
          if (this.updateFlag) {
            mRequest('dayApi/getTheSameDayProductionInfoList', {'dayTime': this.dayTime}, (res) => {

              const dayBatchProductionList = this.R.path(['data', 'list'], res)
              if (!this.R.isEmpty(dayBatchProductionList)) {
                this.dayBatchProductionList = dayBatchProductionList
                this.loading = false
              }else {
                this.loading = false
              }

              const orderDetailList = this.R.path(['data', 'orderList'], res)
              if (!this.R.isEmpty(orderDetailList)) {
                this.orderDetailList=orderDetailList
                this.orderDetailFilterList()
              }

            })
          }else {
            mRequest('dayApi/getBeforeDayProductionInfoByDayTime', {'dayTime': this.dayTime,'beforeClassId':this.beforeClassId}, (res) => {
              const dayBatchProductionList = this.R.path(['data', 'list'], res)
              if (!this.R.isEmpty(dayBatchProductionList)) {
                this.dayBatchProductionList = dayBatchProductionList
                this.loading = false
              }else {
                this.loading = false
              }

              const orderDetailList = this.R.path(['data', 'orderList'], res)
              if (!this.R.isEmpty(orderDetailList)) {
                this.orderDetailList=orderDetailList
                this.orderDetailFilterList()
              }

            })
          }


        }


      }
    }
  }
</script>
